package com.bookstore.controller;

import com.bookstore.entity.Review;
import com.bookstore.service.impl.ReviewServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author Cofe
 * @Date 2022/5/19 12:49
 */
@Controller
@RequestMapping("/review")
public class ReviewController {
    @Resource
    private ReviewServiceImpl reviewService;

    @RequestMapping(
            value = "/addreview",
            method = RequestMethod.POST,
            produces = {"app/xml;charset=UTF-8"}
    )
    @CrossOrigin
    @ResponseBody
    public String addReview(HttpSession httpSession,int book_bid,String book_review){
        if(httpSession.getAttribute("username")==null){
            return "请您先登陆";
        }
        String user_name=httpSession.getAttribute("username")+"";
        String s = reviewService.addReview(book_bid, user_name, book_review);
        return s;
    }

    @RequestMapping(
            value = "/getreview",
            method = RequestMethod.POST
    )
    @CrossOrigin
    @ResponseBody
    public List<Review> getReview(int book_bid){
        List<Review> reviewByid = reviewService.getReviewByid(book_bid);
        return reviewByid;
    }
}
